#include "Tracer.h"
#include "GpioInput.h"
using namespace libemb;

class MyGpioListener:public GpioListener{
private:
    void handleGpio(std::string name, int status)
    {
        if (name=="GPIO1:4") 
        {
            switch (status) {
            case GPIO_STATUS_DOWN:
                TRACE_YELLOW("GPIO1:4 pressed down!\n");
                break;
            case GPIO_STATUS_UP:
                TRACE_CYAN("GPIO1:4 is UP!\n");
                break;
            default:
                TRACE_RED("GPIO1:4 status error!\n");
                break;
            }
        }
    }
};

void TestGpioInput()
{
    MyGpioListener myListener;
    GpioInput *gpioInput = GpioInput::getInstance();
    gpioInput->addGpio("GPIO1:4", GPIO::HIGH, 3000); 
    gpioInput->registerGpioListener(&myListener);
    
    while (1)
    {
        TRACE_YELLOW("-------------GpioInput Test-------------\n");
        TRACE_YELLOW("q/quit: quit.\n");
        TRACE_YELLOW("please input your selection:");
        std::string inputStr;
        std::cin >> inputStr;
        std::cout << inputStr << std::endl;
        if ("q" == inputStr || "quit" == inputStr)
        {
            break;
        }
    }
}
